package com.yimiyisu.contract_cust.controller;

import com.zen.ZenController;
import com.zen.ZenData;
import com.zen.ZenEngine;
import com.zen.ZenResult;
import com.zen.annotation.AccessRole;
import com.zen.annotation.Inject;
import com.zen.annotation.MethodType;
import com.zen.enums.ZenMethod;
import com.zen.enums.ZenRole;

@AccessRole(ZenRole.ADMIN)
public class Category extends ZenController {
    @Inject
    private ZenEngine zenEngine;

    /**
     * 删除合同分类
     */
    @MethodType(ZenMethod.ALL)
    public ZenResult deleteCategory(ZenData data) {
        ZenResult count = zenEngine.execute("count/category",ZenData.create("parentId",data.get("id")));
        if (count.getLong() != 0){
            return ZenResult.fail("该分类下有子分类,请删除子分类再操作");
        }
        ZenResult res = zenEngine.execute("delete/category", data);
        return ZenResult.success().setData(res.getData());
    }

    /**
     * 删除分类
     */
    @MethodType(ZenMethod.ALL)
    public ZenResult deleteMateCategory(ZenData data) {
        ZenResult count = zenEngine.execute("count/mate_cate",ZenData.create("parentId",data.get("id")));
        if (count.getLong() != 0){
            return ZenResult.fail("该分类下有子分类,请删除子分类再操作");
        }
        ZenResult res = zenEngine.execute("delete/mate_cate", data);
        return ZenResult.success().setData(res.getData());
    }
}
